package com.itgan.userbackendmanagement.exception;

import com.itgan.userbackendmanagement.common.enumeration.ErrorCodeEnum;
import com.itgan.userbackendmanagement.common.respondResult.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public Result<?> baseExceptionHandler(BusinessException e){
        log.error("baseException"+e.getMessage(),e);
        return Result.error(e.getCode(),e.getMessage(),e.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public Result<?> baseExceptionHandler(RuntimeException e){
        log.error("runtimeException",e);
        return Result.error(ErrorCodeEnum.SYSTEM_ERROR,e.getMessage(),"");
    }

}
